package com.generator.aboutUser.module.service.impl;

import com.generator.aboutUser.module.dao.ModuleMapper;
import com.generator.aboutUser.module.pojo.Module;
import com.generator.aboutUser.module.service.IModuleService;
import com.generator.aboutUser.user.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @version 1.0
 * @auther wumei
 * @date 2022/01/01
 * 星期六 22:02
 */
@Service
public class ModuleService implements IModuleService {

    @Autowired
    private ModuleMapper moduleMapper;

    public ModuleMapper getModuleMapper() {
        return moduleMapper;
    }
    public void setModuleMapper(ModuleMapper moduleMapper) {
        this.moduleMapper = moduleMapper;
    }

    /**
     * 根据用户查询对应模块
     * @param users
     * @return  返回当前登录用户的模块集合
     */
    @Transactional
    @Override
    public  Module[][] getModulesByUser(Users users) {

        Module[][] modules = new Module[5][10];
        // 把从数据库拿出来的模块按照五大模块分好放入数组中
        for (Module m : moduleMapper.queryModulesByUser(users)) {
            for (int i = 0;i<5;i++){
                if (m.getModulePid() == (i+1)){
                    for (int j = 0; j < 10; j++) {
                        if (modules[i][j] == null){
                            modules[i][j] = m;
                            break;
                        }
                    }
                }
            }
        }
        return modules;
    }



}
